package com.kitking.mybroadcast.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.widget.Toast;

public class NetWorkChange extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context,"网络变了",Toast.LENGTH_LONG).show();

        //ConnectivityManager系统服务类，专门用于管理网络连接的
        ConnectivityManager connectivityManager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo();
        if (networkInfo!=null&&networkInfo.isAvailable()){
            Toast.makeText(context,"network is available",Toast.LENGTH_LONG).show();
        }else {
            Toast.makeText(context,"network is unavailable",Toast.LENGTH_LONG).show();
        }

        if (intent !=null)
        {
            String action=intent.getAction();
            Log.d("ooooooooooo","测试广播。。。。。。。。"+action);


        }
        Toast.makeText(context,"--------测试广播------",Toast.LENGTH_LONG).show();


    }
}
